package lk.icta.core.service.impl;

import lk.icta.core.dao.ObjectionDAO;
import lk.icta.core.entity.Objection;
import lk.icta.core.service.ObjectionManagementService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Kusal Samarakoon
 */
public class ObjectionManagementServiceImpl implements ObjectionManagementService {

    private static final Logger logger = LoggerFactory.getLogger(ObjectionManagementServiceImpl.class);
    private final ObjectionDAO objectionDAO;

    public ObjectionManagementServiceImpl(ObjectionDAO objectionDAO) {
        this.objectionDAO = objectionDAO;
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public void addObjection(Objection objection) {
        objection.getApplicationId();
        logger.debug("Adding a objection {}", objection.getId());
        objectionDAO.addObjection(objection);
    }

    @Transactional(propagation = Propagation.NEVER, readOnly = true)
    public List<Objection> getObjectionByApplicationId(long id) {
        logger.debug("Get a objection {}", id);
        return objectionDAO.getObjectionByApplicationId(id);
    }
}
